package com.puti.doctor.controller;

import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.doctor.domian.GoodsOrder;
import com.puti.doctor.service.IGoodsOrderService;
import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 商品-订单 商品-订单Controller
 * 
 * @author puti
 * @date 2021-04-23
 */
@CrossOrigin
@RestController
@RequestMapping("/order")
public class GoodsOrderController extends BaseController
{
    @Autowired
    private IGoodsOrderService goodsOrderService;

    /**
     * 时间区间查询
     */
    @GetMapping("/findAll")
    public List findAll(@Param("startTime") Date startTime,
                       @Param("endTime") Date endTime){
        return goodsOrderService.findAll(startTime, endTime);
    }

    /**
     * 查询商品-订单 订单状态、支付状态、发货状态、收货状态、筛选、商品搜索（模糊查询
     */
    @GetMapping("/list")
    public TableDataInfo list(GoodsOrder goodsOrder)    {
        startPage();
        List<GoodsOrder> list = goodsOrderService.selectGoodsOrderList(goodsOrder);
        return getDataTable(list);
    }

    /**
     * 导出商品-订单 商品-订单列表
     */
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsOrder goodsOrder) throws IOException
    {
        List<GoodsOrder> list = goodsOrderService.selectGoodsOrderList(goodsOrder);
        ExcelUtil<GoodsOrder> util = new ExcelUtil<GoodsOrder>(GoodsOrder.class);
        util.exportExcel(response, list, "商品-订单 商品-订单数据");
    }

    /**
     * 获取订单详细信息详情页面
     */
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return AjaxResult.success(goodsOrderService.selectGoodsOrderById(orderId));
    }


    /**
     * 新增商品-订单 商品-订单
     */
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsOrder goodsOrder)
    {
        return toAjax(goodsOrderService.insertGoodsOrder(goodsOrder));
    }

    /**
     * 修改商品-订单 商品-订单
     */
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsOrder goodsOrder)
    {
        return toAjax(goodsOrderService.updateGoodsOrder(goodsOrder));
    }

    /**
     * 删除商品订单 商品-订单
     */
    @Log(title = "商品-订单 商品-订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(goodsOrderService.deleteGoodsOrderByIds(orderIds));
    }
}
